from django.shortcuts import render
from django.http import HttpResponse,JsonResponse
from django.contrib.auth.hashers import make_password, check_password
from django.core.urlresolvers import reverse
from we.settings import BASE_DIR
from django.core.paginator import Paginator
from . . import models
import time,os
from django.db.models import Q
from .viewsIndex import uploads

# Create your views here.

# 后台用户列表
def order(request):
    # 获取所有的用户数据
    data = models.Order.objects.all()

    # 获取搜索条件和参数
    types = request.GET.get('types')
    keywords = request.GET.get('keywords')
    
    # 实例化分页类  参数1是所有的数据对象,参数2每页显示条数
    paginator = Paginator(data,7)

    # h获取当前页码数 ?p=n
    p =request.GET.get('p',1) 

    # 获取当前页的数据
    orderlist = paginator.page(p)

    # 分配数据
    context = {'orderlist':orderlist}

    # 添加模板
    return render(request,'myadmin/order/lists.html',context)


# 订单详情
def orderindex(request,vid):
    data = models.OrderInfo.objects.filter(orderid=vid)

    context = {"data":data}
    
    return render(request,'myadmin/order/index.html',context)

def xiala(request):
    datb = request.GET.get('ob')
    data = request.GET.get('oa')

    oc = models.Order.objects.get(id=data)
    oc.status = datb
    oc.save()

    return JsonResponse({'datb':datb})